<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use App\Engine\BaseModel;
use Illuminate\Database\Eloquent\Model;

/**
 * Class User
 *
 * @property int $id
 * @property string|null $openid
 * @property string|null $session_key
 * @property string|null $unionid
 * @property int $login_time
 * @property string|null $nickname
 * @property string|null $avatar
 * @property string|null $phone
 * @property int $created_at
 * @property int $updated_at
 * @property string|null $invite_uid
 * @property string|null $qrcode
 * @property string|null $bind_box_qrcode
 * @property int $points
 * @property int $egg
 * @property int $food
 *
 * @package App\Models
 */
class User extends BaseModel
{
	protected $table = 'users';


	protected $casts = [
		'login_time' => 'int',
		'created_at' => 'int',
		'updated_at' => 'int',
		'points' => 'int',
		'egg' => 'int',
        'draw_times'=>'int'
	];

	protected $fillable = [
		'openid',
		'session_key',
		'unionid',
		'login_time',
		'nickname',
		'avatar',
		'phone',
		'invite_uid',
		'points',
		'egg',
        'draw_times',
        'food',
        'qrcode',
        'gzh_openid',
        'balance',
        'bind_box_qrcode',
        'coupon'
	];


	public $with=["invite"];

	public function invite()
    {
        return $this->belongsTo("App\Models\User","invite_uid","id")->select(["id","nickname","avatar"]);
    }

    public function custom()
    {
        return $this->belongsTo("App\Models\Custom","id","uid");
    }

    public function getLoginTimeAttribute($value)
    {
        return $value!=''?date("Y-m-d H:i:s",$value):'';
    }
}
